﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter23.Exercises
{
    public class Exercise02
    {
        public static void Begin()
        {
            int[] arraySizes = { 100, 1000, 10 * 1000, 100 * 1000, 500 * 1000, 1000 * 1000, 5000 * 1000 };
            foreach (var item in arraySizes)
            {
                var numbers = GenerateLotsOfNumbers(item);
                var queryResults =
                from n in numbers
                where n < 1000
                select n;
                Console.WriteLine("number array size = {0}: count (n < 1000) = {1}", numbers.Length, queryResults.Count());
            }
            Console.WriteLine("Program finished, press Enter Return to continue:");
            Console.ReadLine();
        }

        private static int[] GenerateLotsOfNumbers(int count)
        {
            Random generator = new Random(0);
            int[] result = new int[count];
            for (int i = 0; i < count; i++)
            {
                result[i] = generator.Next();
            }
            return result;
        }
    }
}
